<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Caffe: include/caffe/layer.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Caffe
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_4b7f3da7c7b4301d805dae0326fb91b7.html">caffe</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">layer.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef CAFFE_LAYER_H_</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define CAFFE_LAYER_H_</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;</div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &lt;algorithm&gt;</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &quot;caffe/blob.hpp&quot;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &quot;caffe/common.hpp&quot;</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#include &quot;caffe/layer_factory.hpp&quot;</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &quot;caffe/proto/caffe.pb.h&quot;</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &quot;caffe/util/math_functions.hpp&quot;</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;</div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceboost.html">boost</a> { <span class="keyword">class </span>mutex; }</div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacecaffe.html">caffe</a> {</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00033"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html">   33</a></span>&#160;<span class="keyword">class </span><a class="code" href="classcaffe_1_1Layer.html">Layer</a> {</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a7b4e4ccea08c7b8b15acc6829d5735f6">   40</a></span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1Layer.html#a7b4e4ccea08c7b8b15acc6829d5735f6">Layer</a>(<span class="keyword">const</span> LayerParameter&amp; param)</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    : layer_param_(param) {</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;      <span class="comment">// Set phase and copy blobs (if there are any).</span></div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;      phase_ = param.phase();</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;      <span class="keywordflow">if</span> (layer_param_.blobs_size() &gt; 0) {</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        blobs_.resize(layer_param_.blobs_size());</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; layer_param_.blobs_size(); ++i) {</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;          blobs_[i].reset(<span class="keyword">new</span> <a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>());</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;          blobs_[i]-&gt;FromProto(layer_param_.blobs(i));</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;        }</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;      }</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    }</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;  <span class="keyword">virtual</span> ~<a class="code" href="classcaffe_1_1Layer.html">Layer</a>() {}</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;</div><div class="line"><a name="l00067"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a18d6bfdb535ab8e96a971dec4ae39a84">   67</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Layer.html#a18d6bfdb535ab8e96a971dec4ae39a84">SetUp</a>(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom,</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;      <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top) {</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    CheckBlobCounts(bottom, top);</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    LayerSetUp(bottom, top);</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;    Reshape(bottom, top);</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    SetLossWeights(top);</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;  }</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;</div><div class="line"><a name="l00091"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a481323a3e0972c682787f2137468c29f">   91</a></span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Layer.html#a481323a3e0972c682787f2137468c29f">LayerSetUp</a>(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom,</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;      <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top) {}</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Reshape(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom,</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;      <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top) = 0;</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;  <span class="keyword">inline</span> Dtype Forward(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom,</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;      <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top);</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">void</span> Backward(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top,</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;      <span class="keyword">const</span> vector&lt;bool&gt;&amp; propagate_down,</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;      <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom);</div><div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;</div><div class="line"><a name="l00157"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#aaf4524ce8641a30a8a4784aee1b2b4c8">  157</a></span>&#160;  vector&lt;shared_ptr&lt;Blob&lt;Dtype&gt; &gt; &gt;&amp; <a class="code" href="classcaffe_1_1Layer.html#aaf4524ce8641a30a8a4784aee1b2b4c8">blobs</a>() {</div><div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;    <span class="keywordflow">return</span> blobs_;</div><div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;  }</div><div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;</div><div class="line"><a name="l00164"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#adff82274f146e2b6922d0ebac2aaf215">  164</a></span>&#160;  <span class="keyword">const</span> LayerParameter&amp; <a class="code" href="classcaffe_1_1Layer.html#adff82274f146e2b6922d0ebac2aaf215">layer_param</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> layer_param_; }</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;</div><div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> ToProto(LayerParameter* param, <span class="keywordtype">bool</span> write_diff = <span class="keyword">false</span>);</div><div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;</div><div class="line"><a name="l00174"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a899410336f30821644c8bd6c69a070c9">  174</a></span>&#160;  <span class="keyword">inline</span> Dtype <a class="code" href="classcaffe_1_1Layer.html#a899410336f30821644c8bd6c69a070c9">loss</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> top_index)<span class="keyword"> const </span>{</div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;    <span class="keywordflow">return</span> (loss_.size() &gt; top_index) ? loss_[top_index] : Dtype(0);</div><div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;  }</div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;</div><div class="line"><a name="l00181"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a899b09f4b91ada8545b3a43ee91e0d69">  181</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Layer.html#a899b09f4b91ada8545b3a43ee91e0d69">set_loss</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> top_index, <span class="keyword">const</span> Dtype value) {</div><div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;    <span class="keywordflow">if</span> (loss_.size() &lt;= top_index) {</div><div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;      loss_.resize(top_index + 1, Dtype(0));</div><div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;    }</div><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;    loss_[top_index] = value;</div><div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;  }</div><div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;</div><div class="line"><a name="l00191"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a8952bff6bc4c2a96d8ea30d8ff65b198">  191</a></span>&#160;  <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="classcaffe_1_1Layer.html#a8952bff6bc4c2a96d8ea30d8ff65b198">type</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="stringliteral">&quot;&quot;</span>; }</div><div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;</div><div class="line"><a name="l00200"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a8e5ee0494d85f5f55fc4396537cbc60f">  200</a></span>&#160;  <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Layer.html#a8e5ee0494d85f5f55fc4396537cbc60f">ExactNumBottomBlobs</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> -1; }</div><div class="line"><a name="l00208"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#aca3cb2bafaefda5d4760aaebd0b72def">  208</a></span>&#160;  <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Layer.html#aca3cb2bafaefda5d4760aaebd0b72def">MinBottomBlobs</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> -1; }</div><div class="line"><a name="l00216"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#af8bdc989053e0363ab032026b46de7c3">  216</a></span>&#160;  <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Layer.html#af8bdc989053e0363ab032026b46de7c3">MaxBottomBlobs</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> -1; }</div><div class="line"><a name="l00224"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a64e2ca72c719e4b2f1f9216ccfb0d37f">  224</a></span>&#160;  <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Layer.html#a64e2ca72c719e4b2f1f9216ccfb0d37f">ExactNumTopBlobs</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> -1; }</div><div class="line"><a name="l00232"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#ab9e4c8d642e413948b131d851a8462a4">  232</a></span>&#160;  <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Layer.html#ab9e4c8d642e413948b131d851a8462a4">MinTopBlobs</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> -1; }</div><div class="line"><a name="l00240"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#ac6c03df0b6e40e776c94001e19994a2e">  240</a></span>&#160;  <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classcaffe_1_1Layer.html#ac6c03df0b6e40e776c94001e19994a2e">MaxTopBlobs</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> -1; }</div><div class="line"><a name="l00248"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#af452a938bc7596f9b5e9900c8dc4ab3d">  248</a></span>&#160;  <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classcaffe_1_1Layer.html#af452a938bc7596f9b5e9900c8dc4ab3d">EqualNumBottomTopBlobs</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="keyword">false</span>; }</div><div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;</div><div class="line"><a name="l00258"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a50130669e230a168d1f8fbbb8171f054">  258</a></span>&#160;  <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classcaffe_1_1Layer.html#a50130669e230a168d1f8fbbb8171f054">AutoTopBlobs</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="keyword">false</span>; }</div><div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;</div><div class="line"><a name="l00268"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a1c0b2bffcd6d57e4bd49f820941badb6">  268</a></span>&#160;  <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classcaffe_1_1Layer.html#a1c0b2bffcd6d57e4bd49f820941badb6">AllowForceBackward</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> bottom_index)<span class="keyword"> const </span>{</div><div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;  }</div><div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;</div><div class="line"><a name="l00279"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a1a3708013b0231e71d725252e10ce6e3">  279</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classcaffe_1_1Layer.html#a1a3708013b0231e71d725252e10ce6e3">param_propagate_down</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> param_id) {</div><div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;    <span class="keywordflow">return</span> (param_propagate_down_.size() &gt; param_id) ?</div><div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;        param_propagate_down_[param_id] : <span class="keyword">false</span>;</div><div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;  }</div><div class="line"><a name="l00287"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a9a6fcb843803ed556f0a69cc2864379b">  287</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Layer.html#a9a6fcb843803ed556f0a69cc2864379b">set_param_propagate_down</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> param_id, <span class="keyword">const</span> <span class="keywordtype">bool</span> value) {</div><div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;    <span class="keywordflow">if</span> (param_propagate_down_.size() &lt;= param_id) {</div><div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;      param_propagate_down_.resize(param_id + 1, <span class="keyword">true</span>);</div><div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;    }</div><div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;    param_propagate_down_[param_id] = value;</div><div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;  }</div><div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;</div><div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;</div><div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160; <span class="keyword">protected</span>:</div><div class="line"><a name="l00297"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a7ed12bb2df25c887e41d7ea9557fc701">  297</a></span>&#160;  LayerParameter <a class="code" href="classcaffe_1_1Layer.html#a7ed12bb2df25c887e41d7ea9557fc701">layer_param_</a>;</div><div class="line"><a name="l00299"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a1d04ad7f595a82a1c811f102d68b8a19">  299</a></span>&#160;  Phase <a class="code" href="classcaffe_1_1Layer.html#a1d04ad7f595a82a1c811f102d68b8a19">phase_</a>;</div><div class="line"><a name="l00301"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a8073fcf2c139b47eb99ce71b346b1321">  301</a></span>&#160;  vector&lt;shared_ptr&lt;Blob&lt;Dtype&gt; &gt; &gt; <a class="code" href="classcaffe_1_1Layer.html#a8073fcf2c139b47eb99ce71b346b1321">blobs_</a>;</div><div class="line"><a name="l00303"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#acd4a05def9ff3b42ad72404210613ef7">  303</a></span>&#160;  vector&lt;bool&gt; <a class="code" href="classcaffe_1_1Layer.html#acd4a05def9ff3b42ad72404210613ef7">param_propagate_down_</a>;</div><div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;</div><div class="line"><a name="l00307"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#af6d347229a139500994e7a926c680486">  307</a></span>&#160;  vector&lt;Dtype&gt; <a class="code" href="classcaffe_1_1Layer.html#af6d347229a139500994e7a926c680486">loss_</a>;</div><div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;</div><div class="line"><a name="l00310"></a><span class="lineno">  310</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Forward_cpu(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom,</div><div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;      <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top) = 0;</div><div class="line"><a name="l00316"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#af3a88d8fb290877b4c7eb37daa3499de">  316</a></span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Layer.html#af3a88d8fb290877b4c7eb37daa3499de">Forward_gpu</a>(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom,</div><div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;      <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top) {</div><div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;    <span class="comment">// LOG(WARNING) &lt;&lt; &quot;Using CPU code as backup.&quot;;</span></div><div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;    <span class="keywordflow">return</span> Forward_cpu(bottom, top);</div><div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;  }</div><div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;</div><div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Backward_cpu(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top,</div><div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;      <span class="keyword">const</span> vector&lt;bool&gt;&amp; propagate_down,</div><div class="line"><a name="l00328"></a><span class="lineno">  328</span>&#160;      <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom) = 0;</div><div class="line"><a name="l00334"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a6faee52af6250a38d1b879008257f5a7">  334</a></span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Layer.html#a6faee52af6250a38d1b879008257f5a7">Backward_gpu</a>(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top,</div><div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;      <span class="keyword">const</span> vector&lt;bool&gt;&amp; propagate_down,</div><div class="line"><a name="l00336"></a><span class="lineno">  336</span>&#160;      <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom) {</div><div class="line"><a name="l00337"></a><span class="lineno">  337</span>&#160;    <span class="comment">// LOG(WARNING) &lt;&lt; &quot;Using CPU code as backup.&quot;;</span></div><div class="line"><a name="l00338"></a><span class="lineno">  338</span>&#160;    Backward_cpu(top, propagate_down, bottom);</div><div class="line"><a name="l00339"></a><span class="lineno">  339</span>&#160;  }</div><div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;</div><div class="line"><a name="l00346"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a55c8036130225fbc874a986bdf4b27e2">  346</a></span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Layer.html#a55c8036130225fbc874a986bdf4b27e2">CheckBlobCounts</a>(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom,</div><div class="line"><a name="l00347"></a><span class="lineno">  347</span>&#160;                               <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top) {</div><div class="line"><a name="l00348"></a><span class="lineno">  348</span>&#160;    <span class="keywordflow">if</span> (ExactNumBottomBlobs() &gt;= 0) {</div><div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;      CHECK_EQ(ExactNumBottomBlobs(), bottom.size())</div><div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;          &lt;&lt; type() &lt;&lt; <span class="stringliteral">&quot; Layer takes &quot;</span> &lt;&lt; ExactNumBottomBlobs()</div><div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;          &lt;&lt; <span class="stringliteral">&quot; bottom blob(s) as input.&quot;</span>;</div><div class="line"><a name="l00352"></a><span class="lineno">  352</span>&#160;    }</div><div class="line"><a name="l00353"></a><span class="lineno">  353</span>&#160;    <span class="keywordflow">if</span> (MinBottomBlobs() &gt;= 0) {</div><div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160;      CHECK_LE(MinBottomBlobs(), bottom.size())</div><div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;          &lt;&lt; type() &lt;&lt; <span class="stringliteral">&quot; Layer takes at least &quot;</span> &lt;&lt; MinBottomBlobs()</div><div class="line"><a name="l00356"></a><span class="lineno">  356</span>&#160;          &lt;&lt; <span class="stringliteral">&quot; bottom blob(s) as input.&quot;</span>;</div><div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160;    }</div><div class="line"><a name="l00358"></a><span class="lineno">  358</span>&#160;    <span class="keywordflow">if</span> (MaxBottomBlobs() &gt;= 0) {</div><div class="line"><a name="l00359"></a><span class="lineno">  359</span>&#160;      CHECK_GE(MaxBottomBlobs(), bottom.size())</div><div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;          &lt;&lt; type() &lt;&lt; <span class="stringliteral">&quot; Layer takes at most &quot;</span> &lt;&lt; MaxBottomBlobs()</div><div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;          &lt;&lt; <span class="stringliteral">&quot; bottom blob(s) as input.&quot;</span>;</div><div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;    }</div><div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;    <span class="keywordflow">if</span> (ExactNumTopBlobs() &gt;= 0) {</div><div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;      CHECK_EQ(ExactNumTopBlobs(), top.size())</div><div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;          &lt;&lt; type() &lt;&lt; <span class="stringliteral">&quot; Layer produces &quot;</span> &lt;&lt; ExactNumTopBlobs()</div><div class="line"><a name="l00366"></a><span class="lineno">  366</span>&#160;          &lt;&lt; <span class="stringliteral">&quot; top blob(s) as output.&quot;</span>;</div><div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;    }</div><div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;    <span class="keywordflow">if</span> (MinTopBlobs() &gt;= 0) {</div><div class="line"><a name="l00369"></a><span class="lineno">  369</span>&#160;      CHECK_LE(MinTopBlobs(), top.size())</div><div class="line"><a name="l00370"></a><span class="lineno">  370</span>&#160;          &lt;&lt; type() &lt;&lt; <span class="stringliteral">&quot; Layer produces at least &quot;</span> &lt;&lt; MinTopBlobs()</div><div class="line"><a name="l00371"></a><span class="lineno">  371</span>&#160;          &lt;&lt; <span class="stringliteral">&quot; top blob(s) as output.&quot;</span>;</div><div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;    }</div><div class="line"><a name="l00373"></a><span class="lineno">  373</span>&#160;    <span class="keywordflow">if</span> (MaxTopBlobs() &gt;= 0) {</div><div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;      CHECK_GE(MaxTopBlobs(), top.size())</div><div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;          &lt;&lt; type() &lt;&lt; <span class="stringliteral">&quot; Layer produces at most &quot;</span> &lt;&lt; MaxTopBlobs()</div><div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;          &lt;&lt; <span class="stringliteral">&quot; top blob(s) as output.&quot;</span>;</div><div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;    }</div><div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;    <span class="keywordflow">if</span> (EqualNumBottomTopBlobs()) {</div><div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;      CHECK_EQ(bottom.size(), top.size())</div><div class="line"><a name="l00380"></a><span class="lineno">  380</span>&#160;          &lt;&lt; type() &lt;&lt; <span class="stringliteral">&quot; Layer produces one top blob as output for each &quot;</span></div><div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;          &lt;&lt; <span class="stringliteral">&quot;bottom blob input.&quot;</span>;</div><div class="line"><a name="l00382"></a><span class="lineno">  382</span>&#160;    }</div><div class="line"><a name="l00383"></a><span class="lineno">  383</span>&#160;  }</div><div class="line"><a name="l00384"></a><span class="lineno">  384</span>&#160;</div><div class="line"><a name="l00389"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a04eb2a3d1d59c64cd64c233217d5d6fc">  389</a></span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Layer.html#a04eb2a3d1d59c64cd64c233217d5d6fc">SetLossWeights</a>(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top) {</div><div class="line"><a name="l00390"></a><span class="lineno">  390</span>&#160;    <span class="keyword">const</span> <span class="keywordtype">int</span> num_loss_weights = layer_param_.loss_weight_size();</div><div class="line"><a name="l00391"></a><span class="lineno">  391</span>&#160;    <span class="keywordflow">if</span> (num_loss_weights) {</div><div class="line"><a name="l00392"></a><span class="lineno">  392</span>&#160;      CHECK_EQ(top.size(), num_loss_weights) &lt;&lt; <span class="stringliteral">&quot;loss_weight must be &quot;</span></div><div class="line"><a name="l00393"></a><span class="lineno">  393</span>&#160;          <span class="stringliteral">&quot;unspecified or specified once per top blob.&quot;</span>;</div><div class="line"><a name="l00394"></a><span class="lineno">  394</span>&#160;      <span class="keywordflow">for</span> (<span class="keywordtype">int</span> top_id = 0; top_id &lt; top.size(); ++top_id) {</div><div class="line"><a name="l00395"></a><span class="lineno">  395</span>&#160;        <span class="keyword">const</span> Dtype loss_weight = layer_param_.loss_weight(top_id);</div><div class="line"><a name="l00396"></a><span class="lineno">  396</span>&#160;        <span class="keywordflow">if</span> (loss_weight == Dtype(0)) { <span class="keywordflow">continue</span>; }</div><div class="line"><a name="l00397"></a><span class="lineno">  397</span>&#160;        this-&gt;set_loss(top_id, loss_weight);</div><div class="line"><a name="l00398"></a><span class="lineno">  398</span>&#160;        <span class="keyword">const</span> <span class="keywordtype">int</span> count = top[top_id]-&gt;count();</div><div class="line"><a name="l00399"></a><span class="lineno">  399</span>&#160;        Dtype* loss_multiplier = top[top_id]-&gt;mutable_cpu_diff();</div><div class="line"><a name="l00400"></a><span class="lineno">  400</span>&#160;        caffe_set(count, loss_weight, loss_multiplier);</div><div class="line"><a name="l00401"></a><span class="lineno">  401</span>&#160;      }</div><div class="line"><a name="l00402"></a><span class="lineno">  402</span>&#160;    }</div><div class="line"><a name="l00403"></a><span class="lineno">  403</span>&#160;  }</div><div class="line"><a name="l00404"></a><span class="lineno">  404</span>&#160;</div><div class="line"><a name="l00405"></a><span class="lineno">  405</span>&#160; <span class="keyword">private</span>:</div><div class="line"><a name="l00406"></a><span class="lineno">  406</span>&#160;  DISABLE_COPY_AND_ASSIGN(<a class="code" href="classcaffe_1_1Layer.html">Layer</a>);</div><div class="line"><a name="l00407"></a><span class="lineno">  407</span>&#160;};  <span class="comment">// class Layer</span></div><div class="line"><a name="l00408"></a><span class="lineno">  408</span>&#160;</div><div class="line"><a name="l00409"></a><span class="lineno">  409</span>&#160;<span class="comment">// Forward and backward wrappers. You should implement the cpu and</span></div><div class="line"><a name="l00410"></a><span class="lineno">  410</span>&#160;<span class="comment">// gpu specific implementations instead, and should not change these</span></div><div class="line"><a name="l00411"></a><span class="lineno">  411</span>&#160;<span class="comment">// functions.</span></div><div class="line"><a name="l00412"></a><span class="lineno">  412</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00413"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#ab57d272dabe8c709d2a785eebe72ca57">  413</a></span>&#160;<span class="keyword">inline</span> Dtype <a class="code" href="classcaffe_1_1Layer.html">Layer&lt;Dtype&gt;::Forward</a>(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom,</div><div class="line"><a name="l00414"></a><span class="lineno">  414</span>&#160;    <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top) {</div><div class="line"><a name="l00415"></a><span class="lineno">  415</span>&#160;  Dtype loss = 0;</div><div class="line"><a name="l00416"></a><span class="lineno">  416</span>&#160;  Reshape(bottom, top);</div><div class="line"><a name="l00417"></a><span class="lineno">  417</span>&#160;  <span class="keywordflow">switch</span> (Caffe::mode()) {</div><div class="line"><a name="l00418"></a><span class="lineno">  418</span>&#160;  <span class="keywordflow">case</span> Caffe::CPU:</div><div class="line"><a name="l00419"></a><span class="lineno">  419</span>&#160;    Forward_cpu(bottom, top);</div><div class="line"><a name="l00420"></a><span class="lineno">  420</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> top_id = 0; top_id &lt; top.size(); ++top_id) {</div><div class="line"><a name="l00421"></a><span class="lineno">  421</span>&#160;      <span class="keywordflow">if</span> (!this-&gt;loss(top_id)) { <span class="keywordflow">continue</span>; }</div><div class="line"><a name="l00422"></a><span class="lineno">  422</span>&#160;      <span class="keyword">const</span> <span class="keywordtype">int</span> count = top[top_id]-&gt;count();</div><div class="line"><a name="l00423"></a><span class="lineno">  423</span>&#160;      <span class="keyword">const</span> Dtype* data = top[top_id]-&gt;cpu_data();</div><div class="line"><a name="l00424"></a><span class="lineno">  424</span>&#160;      <span class="keyword">const</span> Dtype* loss_weights = top[top_id]-&gt;cpu_diff();</div><div class="line"><a name="l00425"></a><span class="lineno">  425</span>&#160;      loss += caffe_cpu_dot(count, data, loss_weights);</div><div class="line"><a name="l00426"></a><span class="lineno">  426</span>&#160;    }</div><div class="line"><a name="l00427"></a><span class="lineno">  427</span>&#160;    <span class="keywordflow">break</span>;</div><div class="line"><a name="l00428"></a><span class="lineno">  428</span>&#160;  <span class="keywordflow">case</span> Caffe::GPU:</div><div class="line"><a name="l00429"></a><span class="lineno">  429</span>&#160;    Forward_gpu(bottom, top);</div><div class="line"><a name="l00430"></a><span class="lineno">  430</span>&#160;<span class="preprocessor">#ifndef CPU_ONLY</span></div><div class="line"><a name="l00431"></a><span class="lineno">  431</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> top_id = 0; top_id &lt; top.size(); ++top_id) {</div><div class="line"><a name="l00432"></a><span class="lineno">  432</span>&#160;      <span class="keywordflow">if</span> (!this-&gt;loss(top_id)) { <span class="keywordflow">continue</span>; }</div><div class="line"><a name="l00433"></a><span class="lineno">  433</span>&#160;      <span class="keyword">const</span> <span class="keywordtype">int</span> count = top[top_id]-&gt;count();</div><div class="line"><a name="l00434"></a><span class="lineno">  434</span>&#160;      <span class="keyword">const</span> Dtype* data = top[top_id]-&gt;gpu_data();</div><div class="line"><a name="l00435"></a><span class="lineno">  435</span>&#160;      <span class="keyword">const</span> Dtype* loss_weights = top[top_id]-&gt;gpu_diff();</div><div class="line"><a name="l00436"></a><span class="lineno">  436</span>&#160;      Dtype blob_loss = 0;</div><div class="line"><a name="l00437"></a><span class="lineno">  437</span>&#160;      caffe_gpu_dot(count, data, loss_weights, &amp;blob_loss);</div><div class="line"><a name="l00438"></a><span class="lineno">  438</span>&#160;      loss += blob_loss;</div><div class="line"><a name="l00439"></a><span class="lineno">  439</span>&#160;    }</div><div class="line"><a name="l00440"></a><span class="lineno">  440</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00441"></a><span class="lineno">  441</span>&#160;    <span class="keywordflow">break</span>;</div><div class="line"><a name="l00442"></a><span class="lineno">  442</span>&#160;  <span class="keywordflow">default</span>:</div><div class="line"><a name="l00443"></a><span class="lineno">  443</span>&#160;    LOG(FATAL) &lt;&lt; <span class="stringliteral">&quot;Unknown caffe mode.&quot;</span>;</div><div class="line"><a name="l00444"></a><span class="lineno">  444</span>&#160;  }</div><div class="line"><a name="l00445"></a><span class="lineno">  445</span>&#160;  <span class="keywordflow">return</span> loss;</div><div class="line"><a name="l00446"></a><span class="lineno">  446</span>&#160;}</div><div class="line"><a name="l00447"></a><span class="lineno">  447</span>&#160;</div><div class="line"><a name="l00448"></a><span class="lineno">  448</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00449"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a183d343f5183a4762307f2c5e6ed1e12">  449</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Layer.html">Layer&lt;Dtype&gt;::Backward</a>(<span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; top,</div><div class="line"><a name="l00450"></a><span class="lineno">  450</span>&#160;    <span class="keyword">const</span> vector&lt;bool&gt;&amp; propagate_down,</div><div class="line"><a name="l00451"></a><span class="lineno">  451</span>&#160;    <span class="keyword">const</span> vector&lt;<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>*&gt;&amp; bottom) {</div><div class="line"><a name="l00452"></a><span class="lineno">  452</span>&#160;  <span class="keywordflow">switch</span> (Caffe::mode()) {</div><div class="line"><a name="l00453"></a><span class="lineno">  453</span>&#160;  <span class="keywordflow">case</span> Caffe::CPU:</div><div class="line"><a name="l00454"></a><span class="lineno">  454</span>&#160;    Backward_cpu(top, propagate_down, bottom);</div><div class="line"><a name="l00455"></a><span class="lineno">  455</span>&#160;    <span class="keywordflow">break</span>;</div><div class="line"><a name="l00456"></a><span class="lineno">  456</span>&#160;  <span class="keywordflow">case</span> Caffe::GPU:</div><div class="line"><a name="l00457"></a><span class="lineno">  457</span>&#160;    Backward_gpu(top, propagate_down, bottom);</div><div class="line"><a name="l00458"></a><span class="lineno">  458</span>&#160;    <span class="keywordflow">break</span>;</div><div class="line"><a name="l00459"></a><span class="lineno">  459</span>&#160;  <span class="keywordflow">default</span>:</div><div class="line"><a name="l00460"></a><span class="lineno">  460</span>&#160;    LOG(FATAL) &lt;&lt; <span class="stringliteral">&quot;Unknown caffe mode.&quot;</span>;</div><div class="line"><a name="l00461"></a><span class="lineno">  461</span>&#160;  }</div><div class="line"><a name="l00462"></a><span class="lineno">  462</span>&#160;}</div><div class="line"><a name="l00463"></a><span class="lineno">  463</span>&#160;</div><div class="line"><a name="l00464"></a><span class="lineno">  464</span>&#160;<span class="comment">// Serialize LayerParameter to protocol buffer</span></div><div class="line"><a name="l00465"></a><span class="lineno">  465</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00466"></a><span class="lineno"><a class="line" href="classcaffe_1_1Layer.html#a4a1754828dda22cc8daa2f63377f3579">  466</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="classcaffe_1_1Layer.html">Layer&lt;Dtype&gt;::ToProto</a>(LayerParameter* param, <span class="keywordtype">bool</span> write_diff) {</div><div class="line"><a name="l00467"></a><span class="lineno">  467</span>&#160;  param-&gt;Clear();</div><div class="line"><a name="l00468"></a><span class="lineno">  468</span>&#160;  param-&gt;CopyFrom(layer_param_);</div><div class="line"><a name="l00469"></a><span class="lineno">  469</span>&#160;  param-&gt;clear_blobs();</div><div class="line"><a name="l00470"></a><span class="lineno">  470</span>&#160;  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; blobs_.size(); ++i) {</div><div class="line"><a name="l00471"></a><span class="lineno">  471</span>&#160;    blobs_[i]-&gt;<a class="code" href="classcaffe_1_1Layer.html#a4a1754828dda22cc8daa2f63377f3579">ToProto</a>(param-&gt;add_blobs(), write_diff);</div><div class="line"><a name="l00472"></a><span class="lineno">  472</span>&#160;  }</div><div class="line"><a name="l00473"></a><span class="lineno">  473</span>&#160;}</div><div class="line"><a name="l00474"></a><span class="lineno">  474</span>&#160;</div><div class="line"><a name="l00475"></a><span class="lineno">  475</span>&#160;}  <span class="comment">// namespace caffe</span></div><div class="line"><a name="l00476"></a><span class="lineno">  476</span>&#160;</div><div class="line"><a name="l00477"></a><span class="lineno">  477</span>&#160;<span class="preprocessor">#endif  // CAFFE_LAYER_H_</span></div><div class="ttc" id="classcaffe_1_1Layer_html_a6faee52af6250a38d1b879008257f5a7"><div class="ttname"><a href="classcaffe_1_1Layer.html#a6faee52af6250a38d1b879008257f5a7">caffe::Layer::Backward_gpu</a></div><div class="ttdeci">virtual void Backward_gpu(const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;top, const vector&lt; bool &gt; &amp;propagate_down, const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;bottom)</div><div class="ttdoc">Using the GPU device, compute the gradients for any parameters and for the bottom blobs if propagate_...</div><div class="ttdef"><b>Definition:</b> layer.hpp:334</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_af6d347229a139500994e7a926c680486"><div class="ttname"><a href="classcaffe_1_1Layer.html#af6d347229a139500994e7a926c680486">caffe::Layer::loss_</a></div><div class="ttdeci">vector&lt; Dtype &gt; loss_</div><div class="ttdef"><b>Definition:</b> layer.hpp:307</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_af3a88d8fb290877b4c7eb37daa3499de"><div class="ttname"><a href="classcaffe_1_1Layer.html#af3a88d8fb290877b4c7eb37daa3499de">caffe::Layer::Forward_gpu</a></div><div class="ttdeci">virtual void Forward_gpu(const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;bottom, const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;top)</div><div class="ttdoc">Using the GPU device, compute the layer output. Fall back to Forward_cpu() if unavailable. </div><div class="ttdef"><b>Definition:</b> layer.hpp:316</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html"><div class="ttname"><a href="classcaffe_1_1Layer.html">caffe::Layer</a></div><div class="ttdoc">An interface for the units of computation which can be composed into a Net. </div><div class="ttdef"><b>Definition:</b> layer.hpp:33</div></div>
<div class="ttc" id="namespacecaffe_html"><div class="ttname"><a href="namespacecaffe.html">caffe</a></div><div class="ttdoc">A layer factory that allows one to register layers. During runtime, registered layers can be called b...</div><div class="ttdef"><b>Definition:</b> blob.hpp:14</div></div>
<div class="ttc" id="namespaceboost_html"><div class="ttname"><a href="namespaceboost.html">boost</a></div><div class="ttdef"><b>Definition:</b> internal_thread.hpp:10</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a8073fcf2c139b47eb99ce71b346b1321"><div class="ttname"><a href="classcaffe_1_1Layer.html#a8073fcf2c139b47eb99ce71b346b1321">caffe::Layer::blobs_</a></div><div class="ttdeci">vector&lt; shared_ptr&lt; Blob&lt; Dtype &gt; &gt; &gt; blobs_</div><div class="ttdef"><b>Definition:</b> layer.hpp:301</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a8952bff6bc4c2a96d8ea30d8ff65b198"><div class="ttname"><a href="classcaffe_1_1Layer.html#a8952bff6bc4c2a96d8ea30d8ff65b198">caffe::Layer::type</a></div><div class="ttdeci">virtual const char * type() const</div><div class="ttdoc">Returns the layer type. </div><div class="ttdef"><b>Definition:</b> layer.hpp:191</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_aaf4524ce8641a30a8a4784aee1b2b4c8"><div class="ttname"><a href="classcaffe_1_1Layer.html#aaf4524ce8641a30a8a4784aee1b2b4c8">caffe::Layer::blobs</a></div><div class="ttdeci">vector&lt; shared_ptr&lt; Blob&lt; Dtype &gt; &gt; &gt; &amp; blobs()</div><div class="ttdoc">Returns the vector of learnable parameter blobs. </div><div class="ttdef"><b>Definition:</b> layer.hpp:157</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_ac6c03df0b6e40e776c94001e19994a2e"><div class="ttname"><a href="classcaffe_1_1Layer.html#ac6c03df0b6e40e776c94001e19994a2e">caffe::Layer::MaxTopBlobs</a></div><div class="ttdeci">virtual int MaxTopBlobs() const</div><div class="ttdoc">Returns the maximum number of top blobs required by the layer, or -1 if no maximum number is required...</div><div class="ttdef"><b>Definition:</b> layer.hpp:240</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a04eb2a3d1d59c64cd64c233217d5d6fc"><div class="ttname"><a href="classcaffe_1_1Layer.html#a04eb2a3d1d59c64cd64c233217d5d6fc">caffe::Layer::SetLossWeights</a></div><div class="ttdeci">void SetLossWeights(const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;top)</div><div class="ttdef"><b>Definition:</b> layer.hpp:389</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_acd4a05def9ff3b42ad72404210613ef7"><div class="ttname"><a href="classcaffe_1_1Layer.html#acd4a05def9ff3b42ad72404210613ef7">caffe::Layer::param_propagate_down_</a></div><div class="ttdeci">vector&lt; bool &gt; param_propagate_down_</div><div class="ttdef"><b>Definition:</b> layer.hpp:303</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a8e5ee0494d85f5f55fc4396537cbc60f"><div class="ttname"><a href="classcaffe_1_1Layer.html#a8e5ee0494d85f5f55fc4396537cbc60f">caffe::Layer::ExactNumBottomBlobs</a></div><div class="ttdeci">virtual int ExactNumBottomBlobs() const</div><div class="ttdoc">Returns the exact number of bottom blobs required by the layer, or -1 if no exact number is required...</div><div class="ttdef"><b>Definition:</b> layer.hpp:200</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_af8bdc989053e0363ab032026b46de7c3"><div class="ttname"><a href="classcaffe_1_1Layer.html#af8bdc989053e0363ab032026b46de7c3">caffe::Layer::MaxBottomBlobs</a></div><div class="ttdeci">virtual int MaxBottomBlobs() const</div><div class="ttdoc">Returns the maximum number of bottom blobs required by the layer, or -1 if no maximum number is requi...</div><div class="ttdef"><b>Definition:</b> layer.hpp:216</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a9a6fcb843803ed556f0a69cc2864379b"><div class="ttname"><a href="classcaffe_1_1Layer.html#a9a6fcb843803ed556f0a69cc2864379b">caffe::Layer::set_param_propagate_down</a></div><div class="ttdeci">void set_param_propagate_down(const int param_id, const bool value)</div><div class="ttdoc">Sets whether the layer should compute gradients w.r.t. a parameter at a particular index given by par...</div><div class="ttdef"><b>Definition:</b> layer.hpp:287</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_adff82274f146e2b6922d0ebac2aaf215"><div class="ttname"><a href="classcaffe_1_1Layer.html#adff82274f146e2b6922d0ebac2aaf215">caffe::Layer::layer_param</a></div><div class="ttdeci">const LayerParameter &amp; layer_param() const</div><div class="ttdoc">Returns the layer parameter. </div><div class="ttdef"><b>Definition:</b> layer.hpp:164</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a64e2ca72c719e4b2f1f9216ccfb0d37f"><div class="ttname"><a href="classcaffe_1_1Layer.html#a64e2ca72c719e4b2f1f9216ccfb0d37f">caffe::Layer::ExactNumTopBlobs</a></div><div class="ttdeci">virtual int ExactNumTopBlobs() const</div><div class="ttdoc">Returns the exact number of top blobs required by the layer, or -1 if no exact number is required...</div><div class="ttdef"><b>Definition:</b> layer.hpp:224</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a18d6bfdb535ab8e96a971dec4ae39a84"><div class="ttname"><a href="classcaffe_1_1Layer.html#a18d6bfdb535ab8e96a971dec4ae39a84">caffe::Layer::SetUp</a></div><div class="ttdeci">void SetUp(const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;bottom, const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;top)</div><div class="ttdoc">Implements common layer setup functionality. </div><div class="ttdef"><b>Definition:</b> layer.hpp:67</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a7b4e4ccea08c7b8b15acc6829d5735f6"><div class="ttname"><a href="classcaffe_1_1Layer.html#a7b4e4ccea08c7b8b15acc6829d5735f6">caffe::Layer::Layer</a></div><div class="ttdeci">Layer(const LayerParameter &amp;param)</div><div class="ttdef"><b>Definition:</b> layer.hpp:40</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a1c0b2bffcd6d57e4bd49f820941badb6"><div class="ttname"><a href="classcaffe_1_1Layer.html#a1c0b2bffcd6d57e4bd49f820941badb6">caffe::Layer::AllowForceBackward</a></div><div class="ttdeci">virtual bool AllowForceBackward(const int bottom_index) const</div><div class="ttdoc">Return whether to allow force_backward for a given bottom blob index. </div><div class="ttdef"><b>Definition:</b> layer.hpp:268</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a50130669e230a168d1f8fbbb8171f054"><div class="ttname"><a href="classcaffe_1_1Layer.html#a50130669e230a168d1f8fbbb8171f054">caffe::Layer::AutoTopBlobs</a></div><div class="ttdeci">virtual bool AutoTopBlobs() const</div><div class="ttdoc">Return whether &quot;anonymous&quot; top blobs are created automatically by the layer. </div><div class="ttdef"><b>Definition:</b> layer.hpp:258</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_ab9e4c8d642e413948b131d851a8462a4"><div class="ttname"><a href="classcaffe_1_1Layer.html#ab9e4c8d642e413948b131d851a8462a4">caffe::Layer::MinTopBlobs</a></div><div class="ttdeci">virtual int MinTopBlobs() const</div><div class="ttdoc">Returns the minimum number of top blobs required by the layer, or -1 if no minimum number is required...</div><div class="ttdef"><b>Definition:</b> layer.hpp:232</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a4a1754828dda22cc8daa2f63377f3579"><div class="ttname"><a href="classcaffe_1_1Layer.html#a4a1754828dda22cc8daa2f63377f3579">caffe::Layer::ToProto</a></div><div class="ttdeci">virtual void ToProto(LayerParameter *param, bool write_diff=false)</div><div class="ttdoc">Writes the layer parameter to a protocol buffer. </div><div class="ttdef"><b>Definition:</b> layer.hpp:466</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a1d04ad7f595a82a1c811f102d68b8a19"><div class="ttname"><a href="classcaffe_1_1Layer.html#a1d04ad7f595a82a1c811f102d68b8a19">caffe::Layer::phase_</a></div><div class="ttdeci">Phase phase_</div><div class="ttdef"><b>Definition:</b> layer.hpp:299</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a7ed12bb2df25c887e41d7ea9557fc701"><div class="ttname"><a href="classcaffe_1_1Layer.html#a7ed12bb2df25c887e41d7ea9557fc701">caffe::Layer::layer_param_</a></div><div class="ttdeci">LayerParameter layer_param_</div><div class="ttdef"><b>Definition:</b> layer.hpp:297</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a481323a3e0972c682787f2137468c29f"><div class="ttname"><a href="classcaffe_1_1Layer.html#a481323a3e0972c682787f2137468c29f">caffe::Layer::LayerSetUp</a></div><div class="ttdeci">virtual void LayerSetUp(const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;bottom, const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;top)</div><div class="ttdoc">Does layer-specific setup: your layer should implement this function as well as Reshape. </div><div class="ttdef"><b>Definition:</b> layer.hpp:91</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a899b09f4b91ada8545b3a43ee91e0d69"><div class="ttname"><a href="classcaffe_1_1Layer.html#a899b09f4b91ada8545b3a43ee91e0d69">caffe::Layer::set_loss</a></div><div class="ttdeci">void set_loss(const int top_index, const Dtype value)</div><div class="ttdoc">Sets the loss associated with a top blob at a given index. </div><div class="ttdef"><b>Definition:</b> layer.hpp:181</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a899410336f30821644c8bd6c69a070c9"><div class="ttname"><a href="classcaffe_1_1Layer.html#a899410336f30821644c8bd6c69a070c9">caffe::Layer::loss</a></div><div class="ttdeci">Dtype loss(const int top_index) const</div><div class="ttdoc">Returns the scalar loss associated with a top blob at a given index. </div><div class="ttdef"><b>Definition:</b> layer.hpp:174</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_aca3cb2bafaefda5d4760aaebd0b72def"><div class="ttname"><a href="classcaffe_1_1Layer.html#aca3cb2bafaefda5d4760aaebd0b72def">caffe::Layer::MinBottomBlobs</a></div><div class="ttdeci">virtual int MinBottomBlobs() const</div><div class="ttdoc">Returns the minimum number of bottom blobs required by the layer, or -1 if no minimum number is requi...</div><div class="ttdef"><b>Definition:</b> layer.hpp:208</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a55c8036130225fbc874a986bdf4b27e2"><div class="ttname"><a href="classcaffe_1_1Layer.html#a55c8036130225fbc874a986bdf4b27e2">caffe::Layer::CheckBlobCounts</a></div><div class="ttdeci">virtual void CheckBlobCounts(const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;bottom, const vector&lt; Blob&lt; Dtype &gt; *&gt; &amp;top)</div><div class="ttdef"><b>Definition:</b> layer.hpp:346</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_a1a3708013b0231e71d725252e10ce6e3"><div class="ttname"><a href="classcaffe_1_1Layer.html#a1a3708013b0231e71d725252e10ce6e3">caffe::Layer::param_propagate_down</a></div><div class="ttdeci">bool param_propagate_down(const int param_id)</div><div class="ttdoc">Specifies whether the layer should compute gradients w.r.t. a parameter at a particular index given b...</div><div class="ttdef"><b>Definition:</b> layer.hpp:279</div></div>
<div class="ttc" id="classcaffe_1_1Layer_html_af452a938bc7596f9b5e9900c8dc4ab3d"><div class="ttname"><a href="classcaffe_1_1Layer.html#af452a938bc7596f9b5e9900c8dc4ab3d">caffe::Layer::EqualNumBottomTopBlobs</a></div><div class="ttdeci">virtual bool EqualNumBottomTopBlobs() const</div><div class="ttdoc">Returns true if the layer requires an equal number of bottom and top blobs. </div><div class="ttdef"><b>Definition:</b> layer.hpp:248</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html"><div class="ttname"><a href="classcaffe_1_1Blob.html">caffe::Blob</a></div><div class="ttdoc">A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...</div><div class="ttdef"><b>Definition:</b> blob.hpp:24</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Thu Aug 3 2017 23:11:19 for Caffe by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
